package com.whq.thrift.api.web.admin.service.verify.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.whq.thrift.api.common.spring.datasource.DataSourceContextHolder;
import com.whq.thrift.api.web.admin.db.verify.MerchantKey;
import com.whq.thrift.api.web.admin.db.verify.MerchantKeyMapper;
import com.whq.thrift.api.web.admin.service.verify.MerchantKeyService;

@Service
public class MerchantKeyServiceImpl implements MerchantKeyService {
	@Autowired
	private MerchantKeyMapper merchantKeyMapper;

	public void addRecord(MerchantKey record) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		if (record == null) {
			return;
		}
//		if(UUIDUtil.generateUUID()!=null){
//			record.setPublicKey(UUIDUtil.generateUUID());
//			record.setSignatureKey(UUIDUtil.generateUUID());
//		}
		
		Date date = new Date();
		record.setInsertTime(date);
		this.merchantKeyMapper.addRecord(record);
	}

	public List<MerchantKey> findRecordsByMap(Map<String, Object> whereParams, int beginIndex, int maxCount) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		if (whereParams == null) {
			whereParams = new HashMap<String, Object>(0);
		}
		whereParams.put("beginIndex", beginIndex);
		whereParams.put("maxCount", maxCount);

		return this.merchantKeyMapper.findRecordsByMap(whereParams);
	}

	public void updateRecord(MerchantKey record) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		if (record == null) {
			return;
		}
		this.merchantKeyMapper.updRecord(record);
	}

	public void deleteRecord(String id) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		this.merchantKeyMapper.delRecord(id);
	}

	public int findRecordCount(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		return this.merchantKeyMapper.findRecordsCount(whereParams);
	}

	public MerchantKey findRecordById(String id) {
		DataSourceContextHolder.set("dataSourceSyzsVerify");
		return this.merchantKeyMapper.getRecordByKey(id);
	}

}
